<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="author" content="CarlHuang">
<title>在线预约兑奖</title>
<!--js库及样式-->
<script LANGUAGE="javascript" src="../script/common.js"
	type="text/javascript"></script>
<!--动态js-->
<script type="text/javascript">
	   	var orgid;
	   	var bookOrderid;
	   	var giftruleid;
	   	var giftId;
	   	var account;
	   	var cardCode;
	   	var acclevel;
	     var frozenPoints;
	   	var balance;
	   	      var qt1={};
	   	      var qt3={};
		         function load(){
		        
		        // $("loginform").cardcode.value="9070000000000005";
		         cardCode=$("loginform").cardcode.value;
		      //   alert(cardCode);
	        	    Eui.showNavigation();
			  	setPages(["cardlogindiv","listview2","listview3","listviewmain","showlistdiv","printview"]);
			  
	               }
	               function unload(){
	                 DWR.call('giftStorageService.deleteGiftOrderByStateAndCust',cardCode,function(v){
		      
		          });
	                       orgid=null;
	   	                 bookOrderid=null;
	                  	   giftruleid=null;
	               	   account=null;
	                      cardCode=null;
	                      frozenPoints=null;
	                       balance=null;
	                       $("mainform2").giftName.value="";
	                       $("mainform3").unifiedBuyLevel.value="";
		                  $("mainform2").numeral.value="";
	               	
	               }
		function selOrg(){				
		  	var v = openDialogFrame("/client/show_giftdpi.html?id="+orgid+"&acclevel="+acclevel+"",'选择商品',500,700)
		  
			if (v){		
                    $("giftName").value = v.name;
			      giftruleid=v.id;
			   }
		     }
			function sel2Org(handle,options){
	          var url = spellUrl("/client/show_dpi_station.html",options)
	          openDialogFrame(url,'选择单位',500,800,handle);
               }		//选择单位控件
	          function setOrg1(sorg) {
		     $("mainform3").orgId.value = sorg.id;
	          $("mainform3").unifiedBuyLevel.value = sorg.name;
	          orgid=sorg.id;
	          }
		
			//页面加载方法
	          function login(){
	          cardCode=$("loginform").cardcode.value;
	           DWR.call('giftStorageService.readCardGetCardUser',cardCode,function(v){
		             acclevel=v.currentLevel;      
		             });  
	           
	           DWR.call('giftStorageService.readCardGetAccount',cardCode,function(v){
	        //acclevel=
		           $("userid").innerHTML=cardCode;
		           $("userid2").innerHTML=cardCode
		           $("points").innerHTML=v.balance/100.0;
		           $("points2").innerHTML=v.balance/100.0;
		            balance=v.balance;
		            account=v;
		            
	           
		            DWR.call('giftStorageService.readCardGetCustomer',account.id,function(v){
		                  $("username").innerHTML=v.name;
		                  $("listformmain").custid.value=v.id;
		                   $("username2").innerHTML=v.name;
		                   switchPage('listviewmain');
		                    createTableBookOrder();
		             });
		           
		         });    
	          }  
	          function createTableLocale(){
	       	var columns =[];
		     columns[5]={title:"操作",width:"15%",render:deleteItem};
	          qtLocale= new QueryTable("createQueryLocale_query","mainform2","datalistLocale",columns,"");
	          qtLocale.showTable();	
		     }   
		    function deleteItem(v,r){
		 return "<a href=# onclick=\"deleteItems("+r[5]+");return false;\">删除</a>"
		}
		function deleteItems(bookItemid){
		      DWR.call('giftStorageService.deleteBookItem',bookItemid,function(v){
		           DWR.call('giftStorageService.getBookOrderPoints',bookOrderid,function(v){
	                 $("vpoints2").innerHTML=v;
	                 $("kpoints2").innerHTML=balance-v;
	                 frozenPoints=v;
	                });
	                
	                // $("points").innerHTML=balance; 
	                  createTableLocale();
	                 
		      
		      });   
		}
		  function showDataLocale(){
		  
		  }
		    function dj(){
	              var num=$("numeral").value;
		         if(bookOrderid==null){
		            if(giftruleid!=null&num!=null){
		            DWR.call('giftStorageService.createBookOrder',account.id,cardCode,2,orgid,function(v){
		              $('mainform2').readorderid.value=v.id;
	                   $("vpoints2").innerHTML=v.frozenPoint;
	                    bookOrderid=v.id; 
	              DWR.call('giftStorageService.addBookItem',giftruleid,bookOrderid,num,account.id,account.id,cardCode,function(v){
	              if(v==1){
	               showError("库存数量不足!");
	              }else if(v==2){
	                showError("积分不够!");
	              }else if(v==4){
	               showError("库存礼品不存在!");
	              }else{
	            
	                 
	             $("points").innerHTML=balance;           
		         
		      DWR.call('giftStorageService.getBookOrderPoints',bookOrderid,function(v){ 
		             $("kpoints2").innerHTML=balance-v;
	                       $("vpoints2").innerHTML=v; 
	                       });
	                 createTableLocale();
	           
	              } 
	              });
		         });
		    }
		}else{
		 var b=false;
	       DWR.call('giftStorageService.isGiftRule',giftruleid,bookOrderid,function(v){
	        if(!v){
	    
	       DWR.call('giftStorageService.addBookItem',giftruleid,bookOrderid,num,account.id,cardCode,function(v){
	             
	               if(v==1){
	               showError("库存数量不足!");
	              }else if(v==2){
	                showError("积分不够!");
	              }else if(v==4){
	              showError("库存礼品不存在！");
	              }else{

	                   //  $("points").innerHTML=balance;
               
	                      DWR.call('giftStorageService.getBookOrderPoints',bookOrderid,function(v){ 
	             
	   
	                         $("kpoints2").innerHTML=balance-v;
	                         $("vpoints2").innerHTML=v; 
	               
	                       });
	                    createTableLocale();

	              }
	              });
	    
	       }else{
	           showError("你已经有些礼品了！");
	        $("mainform2").giftName.value="";
		     $("mainform2").numeral.value="";
	           }
	            });
	         }  
	     	}
	          function indpi(){
	          if(orgid==null){
	                showError("请选择兑奖点");
	                
	          }else{ 
	           switchPage('listview2');}
	         
	          }
	          function backlogin(){
	                   orgid=null;
	   	               bookOrderid=null;
	                  	giftruleid=null;
	               	account=null;
	                    frozenPoints=null;
	                     balance=null;
	                       cardCode=$("loginform").cardcode.value;
	                   $("mainform3").unifiedBuyLevel.value="";
	                   $("mainform2").giftName.value="";
	                    
		                  $("mainform2").numeral.value="";
	      
	          switchPage('cardlogindiv');
	          }
	          function back2(){
	                    orgid=null;
	   	               bookOrderid=null;
	                  	giftruleid=null;
	                     balance=null;
	             $("mainform3").unifiedBuyLevel.value="";
	            $("mainform2").giftName.value="";
		       $("mainform2").numeral.value="";
	           switchPage('listview3');
	          }
	          function ToBookOrder(){
	            switchPage('listview3');
	          }
	          function backlist(){
	          $("mainform3").unifiedBuyLevel.value="";
	          orgid=null;
	               switchPage('listviewmain');
	          }
	     function createTableBookOrder(){
		    var columns =[];
			columns[5]={title:"查看",width:"15%",render:showlist}
			qt1 = new QueryTable("createTable2_query","listformmain","datalist1",columns,{
					buttons:[
						{value:"进行预约",actions:ToBookOrder},
						{value:"退出或重新登录",actions:backlogin}
					]
				});
			qt1.showTable();
		}
		function back(){
		       createTableBookOrder();   
		       switchPage("listviewmain"); 
		}
		function showlist(v,r){
		   return "<a href=# onclick=\"showlists('"+r[0]+"','"+r[1]+"','"+r[2]+"','"+r[3]+"',"+r[4]+");return false;\">查看</a>"
		  }
	     function showlists(code,state,plantime,vplantime,points){ 
		          $("vorderid").innerHTML=code;
		            $("orderstate").innerHTML=state; 
                      $("plantime").innerHTML=plantime;
	                 $("exptime").innerHTML=vplantime;
	                 $("point").innerHTML=points;
	         
               $("listform1").bookorderCode.value=code;
               
			     createTable3();
	               switchPage("showlistdiv");
	            
  	
		}
	function createTable3(){
		var columns =[];
		qt3= new QueryTable("createTable3_query","listform1","showlist",columns,{
		       buttons:[{value:"返回",actions:backlist}]});	
		qt3.showTable();
		}
	function dayin(){
		 DWR.call('giftStorageService.freezeBookPoints',cardCode,bookOrderid,function(v){
		       giftId=v.id;
		       requestframe.document.location.href = "print_bespeak_gift.html";
			   switchPage("printview"); 
		 });     
		}
			
		</script>
</head>


<body onload=" load()" onunload="unload()">
<!--页面导航-->
<div class="nav">
<div id="nav">&nbsp;</div>
</div>
<div id="cardlogindiv">

<form id="loginform" name="loginform">

<table>
	<tr>
		<td><label>卡号：</label> <input type="text" name="cardcode">
		</td>
	</tr>
	<tr>
		<td><label>密码：</label> <input id=password type='text'></td>
	</tr>
	<tr>
		<td>
		<button type="button" onclick="login()">进入</button>
		</td>
	</tr>
</table>
</form>
</div>
<div id="datalist"></div>
</div>

<div id="listview3" style="display: none;">
<div class="searchForm">
<form id="mainform3" name="mainform3"><input
	type="hidden" name="orgId" />
<table>
	<td><label>兑奖点选择&nbsp;&nbsp;</label> <input type="text"
		name="unifiedBuyLevel" class="readonly" onblur="checkV(this,'',true)" maxlength="20"> <a
		class="orga" title="选择所属机构" href="javascript:void(0)"
		onclick="sel2Org(setOrg1)">&nbsp;&nbsp;</a><span class="des"> *</span>
	</td>
	<td>
	<td>
	<button type="button" onclick="indpi()">进入</button>
	</td>
	</td>
	<td>
	<td>
	<button type="button" onclick="backlist()">返回</button>
	</td>
	</td>
	<td>
	<button type="button" onclick="backlogin()" align="center">退出或重新登录</button>
	</td>
</table>
</form>
</div>
<div id="datalist"></div>
</div>
<div class="printview" id="printview" style='display:none;'>
	<iframe id="requestframe" name="requestframe" style="width:100%;height:90%;overflow:auto;" frameborder=0 src=""></iframe>
</div>
<div id="listview2" style="display: none;">
<div class=searchForm>
<div class="formTitle">客户信息</div>
<table cellSpacing=0 cellPadding=4 width="100%" border=0>
	<tr>
		<td width=30%><label for="userid">卡号</label> <span name='userid2'
			id='userid2'></span></td>
		<td><label for="username">客户姓名</label> <span name="username2"
			id="username2"></span></td>
		<td><label>账户剩余积分</label> <span name='points2' id='points2'></span></td>
	</tr>
	<tr>
		<td><label>账户可用积分</label> <span name='kpoints2' id='kpoints2'></span></td>
		<td><label>所用积分</label> <span name='vpoints2' id='vpoints2'></span></td>
	</tr>
</table>
</div>
<div class="searchForm">
<form id="mainform2" name="mainform2"><input
	type=hidden id=readorderid name=readorderid>
<table>
	<td><label>奖品名称&nbsp;&nbsp;&nbsp;</label><input type="text"
		name='giftName' id='giftName' onblur="checkV(this,'',true)" readonly
		style="background: #fffccc" /><a class=orga href=# onclick="selOrg()"returnfalse;>&nbsp;&nbsp;&nbsp;</a><span
		class="des"> *</span></td>
	<td><label for=numeral>数量</label> <input id=numeral type='text'
		onblur="checkV(this,'number',true)"></td>
	<td>
	<button type="button" onclick="dj()">增加</button>
	</td>
	<td>
	<button type="button" onclick="back2()">返回</button>
	</td>
	<td>
	<button type="button" onclick="backlogin()" align="center">退出或重新登录</button>
	</td>
</table>
</form>
</div>
<div class=listBorder>
<div class="listBar">
<div class="listTitle">礼品信息列表</div>
</div>
<div id=datalistLocale></div>
</div>
<p>
<button type="button" onclick="dayin()">确认预约</button>
</p>
</div>
<div id="listviewmain" style="display: none">
<div class=searchForm>
<form id='listformmain' name='listformmain' method='POST'
	enctype='multipart/form-data' action='/upload/pic/'><input
	type=hidden id=custid name=custid>
<div class=form>
<div class="formTitle">客户信息</div>
<table cellSpacing=0 cellPadding=4 width="100%" border=0
	class="col3 label6">
	<tr>
		<td width=30%><label>卡号</label> <span name='userid' id='userid'></span></td>
		<td><label>客户姓名</label> <span name="username" id="username"></span></td>
	</tr>
	<tr>
		<td><label>账户剩余积分</label> <span name='points' id='points'></span></td>
		<td></td>
	</tr>
</table>
</div>
</form>
</div>
<div class=listBorder>
<div class="listTitle">礼品兑奖单列表</div>
<div id=datalist1></div>
</div>
</div>
<div id="showlistdiv" style='display:none;'>
		<form id='listform1' name='listform1'>
			<input type=hidden id=bookorderCode name=bookorderCode>
			<div class=form>
				<div class="formTitle">兑奖信息</div>
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="viewTable">
					 <tr>
					    <td><label >兑奖单编号</label> <span name='vorderid' id='vorderid'></span></td>
					 	  <td><label>状态</label> <span name="orderstate" id="orderstate"></span></td>
					</tr>
					<tr>		
					 	   <td><label>预约日期</label> <span name='plantime' id='plantime'></span></td>
					        <td><label>失效日期</label> <span name='exptime' id='exptime'></span></td>
					</tr>	
					<tr>
					    <td><label> 所用积分</label> <span name='point' id='point'></span></td>
					    <td></td>
					</tr>
				</table>
			</div>	 
		</form>
		<div class=listBard>
			<div class="listBar">
				<div class="listTitles">所兑礼品信息</div>
				
			</div>
			<div id=showlist>
			</div>		
			<div class="listBtn" id="listBtn">
				</div>
		
		</div>	
	</div>
</body>
</HTML>